package com.xn.myyxcampus;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.xn.myyxcampus.fragment.MenuFragment;
import com.xn.myyxcampus.fragment.NewsFragment;
import com.xn.myyxcampus.utils.ActivityUtils;

public class MainActivity extends SlidingFragmentActivity {

	/**
	 * 左侧侧滑菜单栏
	 */
	private MenuFragment menu;

	/**
	 * 默认首页新闻页
	 */
	private NewsFragment news;
	/**
	 * 侧滑菜单
	 */
	private SlidingMenu sm;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setBehindContentView(R.layout.left);
		setContentView(R.layout.main);

		news = new NewsFragment();
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, news).commit();
		sm = getSlidingMenu();
		sm.setMode(SlidingMenu.LEFT);
		sm.setBehindWidthRes(R.dimen.slidingmenu_offset);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

		menu = new MenuFragment();
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.menu_frame, menu).commit();
		ActivityUtils.addToActivityStack(MainActivity.this);

	}

	public void switchFragment(Fragment f) {
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, f).commit();
		sm.toggle();
	}
}
